package com.snailhd.filter;

import com.snailhd.entity.Stock;
import com.snailhd.entity.StockDay;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author hd
 * @date 2019-12-16 01:32
 */

@Setter
@Getter
@NoArgsConstructor
public class PriceStocksFilter implements StocksFilter {

    private BigDecimal min;

    private BigDecimal max;

    @Override
    public boolean filter(Stock stock, List<StockDay> list) {
        BigDecimal amount = stock.getAmount();
        if(amount==null) {
            return false;
        }

        if(min!=null && min.compareTo(amount)>0){
            return false;
        }
        if(max!=null && max.compareTo(amount)<0){
            return false;
        }
        return true;
    }
}
